const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()

exports.main = async event => {
  try {
    const { OPENID } = cloud.getWXContext()
    // 删除订阅
    let res = await db
      .collection('messages')
      .where({
        touser: OPENID,
        templateId: event.templateId,
      })
      .remove()
    return res
  } catch (err) {
    console.log(err)
    return err
  }
}
